package com.old.people.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.old.people.entities.Account;
import com.old.people.service.LoginServices;


@RestController
public class LoginController {
//	private static final String REST_URL_PREFIX = "http://OldpeopleService-8001";
//	@Autowired
//	private RestTemplate restTemplate;//提供模板调用，用于微服务与微服务之间的rest调用
	@Autowired
	private LoginServices loginServices; 
	@RequestMapping(value = "/consumer/logins")
	@ResponseBody
	public boolean login(HttpServletRequest request,HttpServletResponse response,@RequestParam("account_id") String account_id,@RequestParam("account_password") String account_password,@RequestParam("account_type") String account_type) {
//		boolean s=restTemplate.getForObject(REST_URL_PREFIX+"/oldpeopleservice/loging", boolean.class);
		boolean flag=loginServices.login(account_id, account_password,account_type);
		if(flag==true) {
			HttpSession session= request.getSession();
			session.setAttribute("account_id", account_id);
		}
		return loginServices.login(account_id, account_password,account_type);
		
	}
	@RequestMapping(value = "/consumer/loginss")
	@ResponseBody
	public boolean login( String account_id,String account_password,String account_type) {
//		boolean s=restTemplate.getForObject(REST_URL_PREFIX+"/oldpeopleservice/loging", boolean.class);
		return loginServices.login(account_id, account_password, account_type);
		
	}
}
